package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.response.sys.NewsCategoryResponse;
import com.mars.common.response.sys.SysUserCommentResponse;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import com.mars.module.admin.request.NewsCategoryRequest;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysUserComment;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.ISysUserCommentService;
import com.mars.module.admin.request.SysUserCommentRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 用户评论控制层
 *
 * @author mars
 * @date 2024-03-18
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "5.用户评论接口管理", tags = "5.用户评论接口管理")
@RequestMapping("/admin/sysUserComment")
public class SysUserCommentController {

    private final ISysUserCommentService iSysUserCommentService;

    /**
     * 分页查询用户评论列表
     */
    @ApiOperation(value = "分页查询用户评论列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysUserComment>> pageList(@RequestBody SysUserCommentRequest sysUserCommentRequest) {
        return R.success(iSysUserCommentService.pageList(sysUserCommentRequest));
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取菜单树")
    public R<List<SysUserCommentResponse>> list(@RequestBody SysUserCommentRequest sysUserCommentRequest) {
        return R.success(iSysUserCommentService.tree(sysUserCommentRequest));
    }

    /**
     * 获取用户评论详细信息
     */
    @ApiOperation(value = "获取用户评论详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysUserComment> detail(@PathVariable("id") Long id) {
        return R.success(iSysUserCommentService.getById(id));
    }

    /**
     * 新增用户评论
     */
    @Log(title = "新增用户评论", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增用户评论")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserCommentRequest sysUserCommentRequest) {
        iSysUserCommentService.add(sysUserCommentRequest);
        return R.success();
    }

    /**
     * 修改用户评论
     */
    @Log(title = "修改用户评论", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改用户评论")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysUserCommentRequest sysUserCommentRequest) {
        iSysUserCommentService.update(sysUserCommentRequest);
        return R.success();
    }

    /**
     * 删除用户评论
     */
    @Log(title = "删除用户评论", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除用户评论")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        iSysUserCommentService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
     * 导出用户评论
     *
     * @param response response
     * @throws IOException IOException
     */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response, @RequestBody SysUserCommentRequest sysUserCommentRequest) throws IOException {
        List<SysUserComment> list = iSysUserCommentService.list(sysUserCommentRequest);
        ExcelUtils.exportExcel(list, SysUserComment.class, "用户评论信息", response);
    }
}
